import request from '../utils/request';

export async function rfm(shopId, branchNo) {
  return await request('/statRFM', {
    params: { shopId, branchNo },
  });
}

// 最近30天销售曲线
export async function statSaleLast30(shopId, branchNo) {
  return await request('/statBranchIncomeLast30d', {
    params: { shopId, branchNo },
  });
}

// 品牌排名
export async function statBrandRank(shopId, branchNo, startDate, endDate) {
  return await request('/statBrandIncome', {
    params: {
      startDate,
      endDate,
      shopId,
      branchNo,
    },
  });
}

// 各店铺贡献
export async function statBranchSale(shopId, startDate, endDate) {
  return await request(`shop/${shopId}/statBranchIncome`, { params: { startDate, endDate } });
}

// 回访统计
export async function statTasks(shopId, branchNo, startDate, endDate, saleMan) {
  return await request('/statVisit', {
    params: {
      shopId, branchNo, startDate, endDate, saleMan,
    },
  });
}

// 会员近一年增长趋势
export async function statVipInc(shopId, branchNo, startDate, endDate) {
  return await request('/statVipInc', {
    params: {
      shopId, branchNo, startDate, endDate,
    },
  });
}

// 我的业绩按月份统计
export async function statBranchRate(shopId, branchNo, startDate, endDate, type) {
  return await request(`/statBranchRate`, {
    params: {
      shopId,
      branchNo,
      startDate,
      endDate,
      type,
    },
  });
}

// 店员-店长 =》 我的业绩 =》业绩排名
export async function statAchvRank(shopId, branchNo, startDate, endDate, type) {
  return await request('/statAchvRank', {
    params: {
      shopId,
      branchNo,
      startDate,
      endDate,
    },
  });
}

// 店员-店长 =》 我的业绩 =》我的业绩
export async function statMyAchv(shopId, branchNo, salemanId, startDate, endDate, type) {
  return await request('/statMyAchv', {
    params: {
      shopId,
      branchNo,
      salemanId,
      startDate,
      endDate,
      type,
    },
  });
}


// 店员-店长 =》 我的业绩 =》新客排名
export async function statAchvVipsRank(shopId, branchNo, startDate, endDate, type) {
  return await request(`shop/${shopId}/branch/${branchNo}/statAchvVips`, {
    params: {
      startDate,
      endDate,
      type,
    },
  });
}

// 店员-店长 =》 我的业绩 =》我的业绩
export async function statMyAchvVips(shopId, branchNo, salemanId, startDate, endDate, type) {
  return await request('/statMyAchvVips', {
    params: {
      shopId,
      branchNo,
      salemanId,
      startDate,
      endDate,
      type,
    },
  });
}

export async function fetchBranchList(shopId, branch_no, showAll = true) {
  const param = { shopId, showAll };
  if (branch_no) {
    param.branch_no = branch_no;
  }
  return await request('/vipCardBranch', {
    params: {
      filter: JSON.stringify(param),
    },
  });
}


export async function fetchSalesmanVisitStat(shopId, id, startDate, endDate) {
  return await request(`/shop/${shopId}/saleman/${id}/statVisit`, {
    params: {
      startDate,
      endDate,
    },
  });
}

export async function fetchGeoBranchList(shopId, point) {
  return await request('/nearByBranches', {
    params: {
      shopId,
      point,
    },
  });
}

export async function fetchStatSGC(shopId, branch_no) {
  let params = {
    shopId,
  };

  if (_.isString(branch_no) && branch_no.length > 0) {
    if (branch_no == "全部") {
       params.branch_no = null;
    } else {
      params.branch_no = branch_no;
    }
  }

  return await request('/statSGC', {
    params: params,
  });
}
